import Blockly from 'blockly/core'
import 'blockly/python_compressed'
import 'blockly/blockly_compressed'
import 'blockly/blocks_compressed'

Blockly.Blocks.logic_contains = {
  init: function () {
    this.appendValueInput('left').setCheck(null)
    this.appendDummyInput().appendField(
      new Blockly.FieldDropdown([
        ['in', 'IN'],
        ['not in', 'NOTIN']
      ]),
      'in_op'
    )
    this.appendValueInput('right').setCheck(null)
    this.setInputsInline(true)
    this.setOutput(true, null)
    this.setColour(230)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

Blockly.Python.logic_contains = function (block) {
  const valueLeft = Blockly.Python.valueToCode(
    block,
    'left',
    Blockly.Python.ORDER_ATOMIC
  )
  const dropdownInOp = block.getFieldValue('in_op')
  const valueRight = Blockly.Python.valueToCode(
    block,
    'right',
    Blockly.Python.ORDER_ATOMIC
  )
  const code = valueLeft + ' ' + dropdownInOp + ' ' + valueRight
  return [code, Blockly.Python.ORDER_NONE]
}

export default Blockly
